define('verifyInput',['jq_validate'],function() {
	jQuery.extend(jQuery.validator.messages,{
		required:'必填字段',
		number:'请输入合法的数字'
	});
	jQuery.validator.addMethod(
		"ip",
		function(value,element){
			var arr = value.split("\.");
    		var len = arr.length;
    		if (len > 4){
    			return false;
    		}else if (len == 0)
    		{
    			if(value < 1 || value >= 255)
    				return  false;
    			
    		}else{
    			return /^(([1-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-4])))\.)(([0-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-4])))\.){2}([0-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-4])))$/.test(value);
    		}
		},
		"IP地址格式不正确"
	);
	jQuery.validator.addMethod(
		"mac",
		function(value,element){
			var arr = value.split("-");
    		var length = arr.length;
    		if(length > 6){
    			return false;
    		}else if(length == 0){
    			return false;
    		}else{
    			if((value.toLowerCase() == 'ff-ff-ff-ff-ff-ff') || (value.toLowerCase() == '00-00-00-00-00-00')){
    				return false;
    			}else {
    				return /^([A-F0-9]{2}-[A-F0-9]{2}-[A-F0-9]{2}-[A-F0-9]{2}-[A-F0-9]{2}-[A-F0-9]{2})$/.test(value);
    			}
    		}
		},
		"MAC地址格式不正确(样例：00-0C-29-0E-D2-4F)"
	);
	jQuery.validator.setDefaults({
//		debug:true,
		errorElement:'div',
		errorClass:'formErrorContent',
		wrapper:'div',
//		showErrors:function(errorMap,errorList){
//			this.defaultShowErrors();
//		},
		errorPlacement:function(error,element){
			var arrow = $('<div>').addClass("formErrorArrow");
			arrow.html('<div class="line10"><!-- --></div><div class="line9"><!-- --></div><div class="line8"><!-- --></div><div class="line7"><!-- --></div><div class="line6"><!-- --></div><div class="line5"><!-- --></div><div class="line4"><!-- --></div><div class="line3"><!-- --></div><div class="line2"><!-- --></div><div class="line1"><!-- --></div>');
			error.insertAfter(element).addClass('formError');
			error.append(arrow);
			var fieldWidth 	= element.width();
			var fieldLeft 	= element.position().left;
			var fieldTop 	=  element.position().top;
			var promptHeight = error.height();
			error.css({top:fieldTop-promptHeight-2+'px',left:fieldLeft+fieldWidth-27+'px'});
		}
	});

	//过滤html tag及多余空白
	function removeHTMLTag(str) {
	  if((typeof str=='string')&&str.constructor==String) {
	    str = str.replace(/(^\s*)|(\s*$)/g,""); //去除首尾空白
	    str = str.replace(/<\/?[^>]*>/g,''); //去除HTML tag
	    str = str.replace(/[ | ]*\n/g,'\n'); //去除行尾空白
	    //str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
	    //str=str.replace(/&nbsp;/ig,'');//去掉&nbsp;
	  }
	  return str;
	}
	//去掉首尾空格
	function trimStr(str){
	  return str.replace(/(^\s*)|(\s*$)/g,"");
	}
	// 如果输入的为空或者不是数字
	function checkIsNum(x){
	  if (isNaN(x) || x == "") {
	     return false;
	  }
	  return true;
	}
	
	//控制上传附件的图片格式
	jQuery.fn.extend({
        uploadPreview: function(opts) {
            opts = jQuery.extend({
                width: 0,
                height: 0,
                imgDiv: "#imgDiv",
                maxSize:3,
                imgType: ["gif", "jpeg", "jpg", "bmp", "png"],
                callback: function() { return false; }
            }, opts || {});
            //var _self = this;
            var _this = $(this);
            var imgDiv = $(opts.imgDiv);
            imgDiv.width(opts.width);
            imgDiv.height(opts.height);
            var version = parseInt($.support.version,10);
			
            
            autoScaling = function() {
            	
                if (version == 7 || version == 8  || version == 9)
				imgDiv.get(0).filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = "image";
                var img_width = imgDiv.width();
                var img_height = imgDiv.height();
                if (img_width > 0 && img_height > 0) {
                    var rate = (opts.width / img_width < opts.height / img_height) ? opts.width / img_width : opts.height / img_height;
                    if (rate <= 1) {
                        if (version == 7 || version == 8  || version == 9) 
						imgDiv.get(0).filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = "scale";
                        imgDiv.width(img_width * rate);
                        imgDiv.height(img_height * rate);
                    } else {
                        imgDiv.width(img_width);
                        imgDiv.height(img_height);
                    }
                    var left = (opts.width - imgDiv.width()) * 0.5;
                    var top = (opts.height - imgDiv.height()) * 0.5;
                    imgDiv.css({ "margin-left": left, "margin-top": top });
                    //imgDiv.show();
                }
            },
            
            createImg = function(){
        		imgDiv.html('');
        		
                var img = $("<img />");
                imgDiv.replaceWith(img);
                imgDiv = img;
            },
   
            _this.change(function() {
            	
                if (this.value) {
                    if (!RegExp("\.(" + opts.imgType.join("|") + ")$", "i").test(this.value.toLowerCase())) {
                        //alert("图片类型必须是" + opts.imgType.join(". ") + "中的一种");
                        webComm.swalAlert("图片类型必须是" + opts.imgType.join("、 ") + "中的一种");
                        this.value = "";
                        return false;
                    }
                    //imgDiv.hide();
                    if ($.support.msie && version < 10) {
                    	
                        if (version == 6) {
                        	
                            var image = new Image();
                            image.onload = function(){
                                if( (image.fileSize/1024/1024) > opts.maxSize) {
                                	//alert('图片大小不能超过'+opts.maxSize+'M');
                                	webComm.swalAlert('图片大小不能超过'+opts.maxSize+'M');
                                	return false;
                                }
                            }
                            image.src = 'file:///' + this.value;

                            createImg();
                            imgDiv.attr('src', image.src);
                            autoScaling();
                        }  else {
                        	
                        	this.select();
                        	var img = document.selection.createRange().text;
                            var image = new Image();
                            image.onload = function(){
                                if( (image.fileSize/1024/1024) > opts.maxSize) {
                                	webComm.swalAlert('图片大小不能超过'+opts.maxSize+'M');
                                	return false;
                                }
                            }
                            image.src = img;                        	
                            
                        	imgDiv.html('');                        	
                            imgDiv.css({ filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image)" });
                            imgDiv.get(0).filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = "image";                           
                            
                            try {
                                imgDiv.get(0).filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = img;
                            } catch (e) {
                                //alert("无效的图片文件！");
                                webComm.swalAlert("无效的图片文件！");
                                return;
                            }                            
                            
                            setTimeout("autoScaling()", 100);                            
                        }
                    }
                    else {
                    	try{   
                    		var file = null;
                    		var size = 0;
                    		if(this.files && this.files[0] ){
                    			file = this.files[0]; 
                    			size = file.size;
                    		}else if(this.files && this.files.item(0)) {                    			
                    			file = this.files.item(0);   
                    			size = file.fileSize;
                    	    } 
 
                    		if((size/1024/1024) > opts.maxSize){
                    			//alert('图片大小不能超过'+opts.maxSize+'M');
                    			webComm.swalAlert('图片大小不能超过'+opts.maxSize+'M');
                            	return false;
                			}
                			
                			createImg();
                    		
                    		//Firefox 因安全性问题已无法直接通过input[file].value 获取完整的文件路径
                    		try{
                    			//Firefox7.0 以下                    			
                    			imgDiv.attr('src', file.getAsDataURL());
                    		}catch(e){
                    			//Firefox8.0以上                    			
                    			imgDiv.attr('src', window.URL.createObjectURL(file));
                    		}
                    		
	                        imgDiv.css({ "vertical-align": "middle" });
	                        setTimeout("autoScaling()", 100);
                    	}catch(e){                    		
                    		//支持html5的浏览器,比如高版本的firefox、chrome、ie10
                    		if (this.files && this.files[0]) {                    		
                    			if((this.files[0].size/1024/1024) > opts.maxSize){
                                	//alert('图片大小不能超过'+opts.maxSize+'M');
                                	webComm.swalAlert('图片大小不能超过'+opts.maxSize+'M');
                                	return false;
                    			}
                    			
                    	        var reader = new FileReader(); 
                    	        reader.onload = function (e) {                      	        	
                    	        	imgDiv.attr('src', e.target.result);  
                    	        };
                    	        reader.readAsDataURL(this.files[0]); 
                    	        setTimeout("autoScaling()", 100);
                    	    }  
                    	};
                    }
                }
            });
        }
    });
});